package com.zxmr.domain.service;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.zxmr.CommonInit;
import com.zxmr.db.DBManager;
import com.zxmr.domain.SurgeryAppointment;

public class SurgeryAppointmentService {

	DBManager db = CommonInit.getDBManager();
	
	public boolean add(SurgeryAppointment ca)
	{
		try
		{
			db.getMapper().insert("surgeryAppointment.add", ca);
			return true;
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		return false;
	}
	public boolean delete(SurgeryAppointment ca)
	{
		try
		{
			db.getMapper().delete("surgeryAppointment.delete", ca.getId());
			return true;
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		return false;
	}
	
	public boolean update(SurgeryAppointment ca)
	{
		try
		{
			db.getMapper().delete("surgeryAppointment.update", ca);
			return true;
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		return false;
	}
	public SurgeryAppointment query(long id)
	{
		try
		{
			return (SurgeryAppointment)db.getMapper().queryForObject("surgeryAppointment.findByID", id);
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		return null;
	}
	@SuppressWarnings("unchecked")
	public List<SurgeryAppointment> queryAll(int company)
	{
		try
		{
			return (List<SurgeryAppointment>)db.getMapper().queryForList("surgeryAppointment.findByCompany", company);
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		return null;
	}
	@SuppressWarnings("unchecked")
	public List<SurgeryAppointment> queryCAPagination(int start,int limit,int company)
	{
		Map<String,Object> para = new HashMap<String,Object>();
		para.put("start", start);
		para.put("limit", limit);
		para.put("company", company);
		
		try {
			return (List<SurgeryAppointment>)db.getMapper().queryForList("surgeryAppointment.findByCompanyPagination", para);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public int getTotalCount(int company)
	{
		try
		{
			return (Integer)db.getMapper().queryForObject("surgeryAppointment.findCountByCompany", company);
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		return 0;
	}
}
